<template>
  <div class="app-container bg-gray">
    <el-card class="box-1">
      <div slot="header"><span>题目详情</span></div>
      <el-form :model="form" label-width="160px">
        <el-form-item label="题目标题">
          {{ form['name'] }}
        </el-form-item>
        <el-form-item label="附图">
          <el-image :src="form['annex']" :preview-src-list="[form['annex']]" style="width: 188px; height: 100px;"/>
        </el-form-item>
        <el-form-item label="必填">
          {{ form['isMust'] }}
          <label v-if="form['must']===1">是</label>
          <label v-else>否</label>
        </el-form-item>
        <el-form-item label="题目类型">
          <label v-if="form['type']===1">单选题</label>
          <label v-else-if="form['type']===2">多选题</label>
          <label v-else>填空题</label>
        </el-form-item>
        <el-form-item v-if="form['type']!==3" label="题目选项">
          <div
            v-for="(questionAnswerItem, questionAnswerIndex) in form['option']"
            :key="questionAnswerIndex">
            {{ questionAnswerItem['label'] +'： ' + questionAnswerItem['value'] }}
          </div>
        </el-form-item>
        <el-form-item label="正确答案">
          <label v-if="form['type']===1">{{ answerIndex[form['answer']] }}</label>
          <div v-if="form['type']===2">
            <label v-for="item in form['answer2']" :key="item">{{ answerIndex[item] }}</label>
          </div>
          <label v-if="form['type']===3">{{ form['answer'] }}</label>
        </el-form-item>
        <el-form-item label="题目分数">
          {{ form['fraction'] }}
        </el-form-item>
        <el-form-item label="题目分析">
          <div v-html="form['remarks']">{{ form['remarks'] }}</div>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      answerIndex: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],

      form: {
        id: '',
        itemId: '',
        name: '',
        annex: '',
        type: 1,
        must: 1,
        option: [{label: 'A', value: ''}],
        answer: 0,
        answer2: [],
        fraction: '',
        remarks: ''
      }
    }
  },
  watch: {},
  created() {
    this.form['id'] = this.$route.query.id;
    this.form['itemId'] = this.$route.query.itemId;
    this.getData();
  },
  methods: {
    getData() {
      const url = 'exam/itemInfo/' + this.form['itemId'];
      this.$store.dispatch('GetConnect', { url }).then(res => {
        this.form = res.data
        if (this.form['type'] === 1) {
          this.form['answer'] = this.form['answer'][0];
        } else if (this.form['type'] === 2) {
          this.form['answer2'] = this.form['answer'];
        }
        this.form['id'] = this.$route.query.id;
        this.form['itemId'] = this.$route.query.itemId;
      }).catch(e => {
        this.$message.error(e.msg + ',请刷新或联系管理员')
      })
    }
  }
}
</script>

<style lang="scss" type="text/scss" scoped>
@import '../../../../styles/index.scss';
.box-1 {
  max-width: 1000px;
  margin: 0 auto;
  > div span {
    font-size: 18px;
    font-weight: 600;
    padding: 0 10px;
  }
  .el-form {
    max-width: 900px;
    .title {
      font-weight: 600;
    }
    .remark {
      font-size: 13px;
      color: $textGray;
    }
    .el-button {
      width: 20%;
      min-width: 160px;
    }
  }
}
.el-checkbox {
  margin-right: 30px;
}
.el-checkbox + .el-checkbox {
  margin-left: 0;
  margin-right: 30px;
}
</style>
